<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="/js/axios.min.js"></script>
<script src="/js/util.js"></script>
<script>
    var channelId;
    window.onload = function () {
        channelId = getQuery("channelId");
        findByItem(1);
    }

    function findByItem(pageNO) {


        axios.get("/post/findByItem", {
            params: {
                pageNO,
                channelId,
                title: $("title").value,
                username: $("username").value,
                startDate: $("startDate").value,
                endDate: $("endDate").value
            }
        }).then(resp => {
            var info = resp.data;
            var str = "";
            info.records.forEach(p => {
                str += `<tr><td><a href="/replay.html?postId=${p.id}">${p.title}</a></td><td>${p.user.username}</td>
                        <td>${p.replayNum}</td><td>${p.time}</td></tr>`;
            })
            $("postData").innerHTML = str;
            var pageStr = "";

            for (let i = 1; i <= info.pages; i++) {
                pageStr += `<a style="margin-left: 10px" href="javascript:findByItem(${i})">${i}</a>`;
            }
            $("postCut").innerHTML = pageStr;

        })
    }

    function addPost() {
        location.href = "/addPost.html?channelId=" + getQuery("channelId");
    }

</script>

<body>
主题名称：<input type="text" id="title">
作者：<input type="text" id="username">
起始日期：<input type="text" id="startDate">
结束日期：<input type="text" id="endDate">
<input type="button" value="搜索" onclick="findByItem(1)">
<a href="javascript:addPost()">发表话题</a>
<table border="1" width="100%" cellspacing="1">
    <thead>
    <tr>
        <th>主题</th>
        <th>作者</th>
        <th>回帖数量</th>
        <th>发帖时间</th>
    </tr>
    </thead>
    <tbody id="postData"></tbody>
</table>
<div id="postCut"></div>

</body>
</html>